home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / user / performancerating.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  8KB  |  299 lines

  1. /* Mode=Run */
  2. /* ***********************************************************************
  3.  
  4.    PERFORMANCE RATING PROGRAM FOR FOOTBALL REXX SUITE
  5.   ----------------------------------------------------
  6.  
  7.     Copyright  Mark Naughton 1998
  8.                                         From an idea by Steve Holland
  9.  
  10. Version    Date     History
  11. --------------------------------------------------------------------------
  12.  1.0       160998   First release. Will give different tables according to
  13.                     the values set below.
  14.            230998   Bug found where the values to be calculated for the
  15.                     position were summed to be Zero - Program failed.
  16.                     Fixed.
  17.            250899   Added error msg to file checks.
  18.            280899   Converted to use locale. Some error messages, before
  19.                     reading the locale, will still be in English.
  20.  
  21. **************************************************************************
  22.  
  23. Procedure
  24. ---------
  25.  
  26. 1. Check files exist. Open 'Teams.df'.
  27. 2. Read in teams and their associated data; WIN, DRAW, LOST etc.
  28. 3. Close file.
  29. 4. Open 'Teams.sf' for reading.
  30. 5. Read each line that has a game played, and from that get the team names
  31.    and the score. Then update the relevant team data with the result.
  32. 6. Format data in form of a league table to two arrays.
  33. 8. Sort array.
  34. 9. Display table and exit.
  35.  
  36. ************************************************************************** */
  37. PARSE ARG league_file
  38.  
  39. version = 1
  40.  
  41. hgfp = 1          /* Points to be added for each goal scored at Home */
  42. hgap = 1.5        /* Points to be added for each goal scored against at Home */
  43. hcsp = 2          /* Points to be added for each clean sheet at Home */
  44. hpts = 1          /* Points to be added for points received at Home */
  45. agfp = 1.5        /* Points to be added for each goal scored Away */
  46. agap = 1          /* Points to be added for each goal scored against Away */
  47. acsp = 3          /* Points to be added for each clean sheet Away */
  48. apts = 1.5        /* Points to be added for points received Away */
  49. switch = 0
  50.  
  51. league_file  = "Data/" || league_file
  52. input2_file  = '.sf'
  53. input3_file  = '.df'
  54. title        = '*LEAGUE_NAME='
  55. points_win   = '*POINTS_PER_WIN='
  56. points_drw   = '*POINTS_PER_DRW='
  57. points_lse   = '*POINTS_PER_LSE='
  58. separator    = '*'
  59. teams.       = '???'
  60. teams2.      = '???'
  61. h_gof.       = '???'
  62. h_goa.       = '???'
  63. h_pts.       = '???'
  64. h_cls.       = '???'
  65. h_gms.       = '???'
  66. a_gof.       = '???'
  67. a_goa.       = '???'
  68. a_pts.       = '???'
  69. a_cls.       = '???'
  70. a_gms.       = '???'
  71. t_num.       = '???'
  72. ptswin       = 2
  73. ptsdrw       = 1
  74. ptslse       = 0
  75. not_played   = '__   __'
  76.  
  77.  
  78. if open(datafile,"Data/Football.locale",'r') then do
  79.    line = readln(datafile)
  80.    locdir = strip(line)
  81.    close(datafile)
  82. end
  83. else do
  84.    say
  85.    say "ERROR :    (PerformanceRating)"
  86.    say
  87.    say "Cannot read 'Data/Football.locale' for the locale settings."
  88.    exit
  89. end
  90.  
  91. locdir = locdir"User/PerformanceRating.data"
  92.  
  93. if open(datafile,"ENV:FootballRXPath",'r') then do
  94.    line = readln(datafile)
  95.    rxdir = strip(line)
  96.    close(datafile)
  97. end
  98. else
  99.    rxdir = "SYS:Rexxc/"
  100.  
  101. if exists(locdir) > 0 then do
  102.   address command rxdir'rx 'locdir
  103.   VarCount = getclip('VarCount')
  104.   do i = 1 to VarCount
  105.     interpret getclip('var.'i)
  106.   end
  107. end
  108. else do
  109.    say
  110.    say "ERROR :    (PerformanceRating)"
  111.    say
  112.    say "Cannot find '"locdir"' to read locale settings."
  113.    exit
  114. end
  115.  
  116. if exists(league_file || input2_file) = 0 then do
  117.    say
  118.    say pr_error
  119.    say
  120.    say pr_one"'"league_file || input2_file"'."
  121.    exit
  122. end
  123.  
  124. if exists(league_file || input3_file) = 0 then do
  125.    say
  126.    say pr_error
  127.    say
  128.    say pr_one"'"league_file || input3_file"'."
  129.    exit
  130. end
  131.  
  132. tcount = 0
  133. if open(datafile,league_file || input3_file,'r') then do
  134.    do while ~eof(datafile)
  135.       line = readln(datafile)
  136.       if pos(title,line) > 0 then        league_title = delstr(line,1,13)
  137.       if pos(points_win,line) > 0 then   ptswin=delstr(line,1,16)
  138.       if pos(points_drw,line) > 0 then   ptsdrw=delstr(line,1,16)
  139.       if pos(points_lse,line) > 0 then   ptslse=delstr(line,1,16)
  140.       if pos(separator,line) = 0 then do
  141.          line = strip(line)
  142.          tcount       = tcount + 1
  143.          teams.tcount = line
  144.       end
  145.    end
  146.    close(datafile)
  147. end
  148. else do
  149.    say
  150.    say pr_error
  151.    say
  152.    say pr_two"'"league_file || input3_file"'."
  153.    exit
  154. end
  155.  
  156. do i=1 to tcount
  157.    h_gof.i = 0
  158.    h_goa.i = 0
  159.    h_pts.i = 0
  160.    h_cls.i = 0
  161.    h_gms.i = 0
  162.    a_gof.i = 0
  163.    a_goa.i = 0
  164.    a_pts.i = 0
  165.    a_cls.i = 0
  166.    a_gms.i = 0
  167. end
  168.  
  169. if open(datafile,league_file || input2_file,'r') then do
  170.    do while ~eof(datafile)
  171.       line = readln(datafile)
  172.       if pos(separator,line) = 0 then do
  173.          if pos(not_played,line) = 0 then do
  174.             home_team = strip(substr(line,1,30))
  175.             goals_for = substr(line,32,2)
  176.             goals_aga = substr(line,37,2)
  177.             away_team = strip(substr(line,41,30))
  178.  
  179.             do i=1 to tcount
  180.                if home_team = teams.i then do
  181.                   h_gof.i = h_gof.i + goals_for
  182.                   h_goa.i = h_goa.i + goals_aga
  183.                   h_gms.i = h_gms.i + 1
  184.                   if goals_aga = 0 then
  185.                      h_cls.i = h_cls.i + 1
  186.                   if goals_for = goals_aga then
  187.                      h_pts.i = h_pts.i + ptsdrw
  188.                   if goals_for < goals_aga then
  189.                      h_pts.i = h_pts.i + ptslse
  190.                   if goals_for > goals_aga then
  191.                      h_pts.i = h_pts.i + ptswin
  192.                end
  193.             end
  194.             do i=1 to tcount
  195.                if away_team = teams.i then do
  196.                   a_gof.i = a_gof.i + goals_aga
  197.                   a_goa.i = a_goa.i + goals_for
  198.                   a_gms.i = a_gms.i + 1
  199.                   if goals_for = 0 then
  200.                      a_cls.i = a_cls.i + 1
  201.                   if goals_for = goals_aga then
  202.                      a_pts.i = a_pts.i + ptsdrw
  203.                   if goals_for < goals_aga then
  204.                      a_pts.i = a_pts.i + ptswin
  205.                   if goals_for > goals_aga then
  206.                      a_pts.i = a_pts.i + ptslse
  207.                end
  208.             end
  209.          end
  210.       end
  211.    end
  212.    close(datafile)
  213. end
  214. else do
  215.    say
  216.    say pr_error
  217.    say
  218.    say pr_two"'"league_file || input2_file"'."
  219.    exit
  220. end
  221.  
  222. do i=1 to tcount
  223.    hp1 = ((h_gof.i * hgfp) + (h_cls.i * hcsp) + (h_pts.i * hpts))
  224.    hp2 =(h_goa.i * hgap)
  225.    hp = hp1-hp2
  226.    ap1 = ((a_gof.i * agfp) + (a_cls.i * acsp) + (a_pts.i * apts))
  227.    ap2 = (a_goa.i * agap)
  228.    ap = ap1-ap2
  229.    if switch = 1 then do
  230.       hp = trunc(hp / h_gms.i,3)
  231.       ap = trunc(ap / a_gms.i,3)
  232.    end
  233.    t_num.i = trunc(hp + ap,3)
  234. end
  235.  
  236. do i=1 to tcount
  237.    line = teams.i
  238.    line = insert(" ",line,length(line)+1,30-length(line))
  239.    hg = right(h_gms.i,3)
  240.    hf = right(h_gof.i,3)
  241.    ha = right(h_goa.i,3)
  242.    hc = right(h_cls.i,3)
  243.    hp = right(h_pts.i,3)
  244.    ag = right(a_gms.i,3)
  245.    af = right(a_gof.i,3)
  246.    aa = right(a_goa.i,3)
  247.    ac = right(a_cls.i,3)
  248.    ap = right(a_pts.i,3)
  249.    teams.i = line"    "hg"  "hf"  "ha" "hc" "hp"   "ag"  "af"  "aa" "ac" "ap"      "right(t_num.i,7,' ')
  250.    teams2.i= line"    "hg"  "hf"  "ha" "hc" "hp"   "ag"  "af"  "aa" "ac" "ap"      "right(t_num.i,7,' ')
  251. end
  252.  
  253. ctr = 0
  254. do while swapctr > 0
  255.    swapctr=9
  256.    do i=1 to tcount-1
  257.       swapdone=0
  258.       j = i + 1
  259.       if strip(substr(teams.i,84,12)) < strip(substr(teams.j,84,12)) then do
  260.          teams.i = teams2.j
  261.          teams.j = teams2.i
  262.          teams2.i= teams.i
  263.          teams2.j= teams.j
  264.          swapdone= 1
  265.          ctr = ctr + 1
  266.       end
  267.       if swapdone = 1 then
  268.          break
  269.    end
  270.    if ctr = 0 then
  271.       swapctr = 0
  272.    else
  273.       ctr = 0
  274. end
  275.  
  276. /* ---------------------------------------------- */
  277.  
  278. say
  279. say center(pr_three"'"league_title"'",88)
  280. say "-------------------------------------------------------------------------------------------------"
  281. say
  282. if switch = 1 then
  283.    say pr_four
  284. say
  285. say pr_txt1
  286. say
  287. say pr_txt2
  288. say "-------------------------------------------------------------------------------------------------"
  289.  
  290. do i=1 to tcount
  291.    if i<10 then
  292.       say " "i"  "teams.i
  293.    else
  294.       say i"  "teams.i
  295. end
  296. say "-------------------------------------------------------------------------------------------------"
  297. say
  298.  
  299. exit